@extends('public.father')
@section('css')

	<link href="/templates/hd/assets/AmazeUI-2.4.2/assets/css/amazeui.css" rel="stylesheet" type="text/css" />
	<link href="/templates/hd/assets/basic/css/demo.css" rel="stylesheet" type="text/css" />
	<link href="/templates/hd/assets/css/cartstyle.css" rel="stylesheet" type="text/css" />
	<link href="/templates/hd/assets/css/optstyle.css" rel="stylesheet" type="text/css" />

	@endsection

@section('script')
	<script type="text/javascript" src="/templates/hd/assets/js/jquery.js"></script>
	<script type="text/javascript" src="/templates/hd/assets/js/Calculation.js"></script>
	<script>
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
	</script>



@endsection

@section('content')
			<div class="clear"></div>

			<!--购物车 -->

			@if(count($card))


			<div class="concent">
				<div id="cartTable">
					<div class="cart-table-th">
						<div class="wp">
							<div class="th th-chk">
								<div id="J_SelectAll1" class="select-all J_SelectAll">

								</div>
							</div>
							<div class="th th-item">
								<div class="td-inner">商品信息</div>
							</div>
							<div class="th th-price">
								<div class="td-inner">单价</div>
							</div>
							<div class="th th-amount">
								<div class="td-inner">数量</div>
							</div>
							<div class="th th-sum">
								<div class="td-inner">金额</div>
							</div>
							<div class="th th-op">
								<div class="td-inner">操作</div>
							</div>
						</div>
					</div>
					<div class="clear"></div>






						<tr class="item-list">
							<div class="bundle  bundle-last ">

								<div class="clear"></div>



								@foreach($card as $v)

									<div class="bundle-main">

										<ul class="item-content clearfix">
											<li class="td td-chk">
												<div class="cart-checkbox ">
													<input class="check haha" id="J_CheckBox_170037950254" name="items" value="170037950254" type="checkbox">
													<label for="J_CheckBox_170037950254"></label>
												</div>
											</li>
											<li class="td td-item">
												<div class="item-pic">
													<a href="#" target="_blank" data-title="美康粉黛醉美东方唇膏口红正品 持久保湿滋润防水不掉色护唇彩妆" class="J_MakePoint" data-point="tbcart.8.12">
														<img src="{{explode(',',$v->good['pics'])[0]}}" class="itempic J_ItemImg"></a>
												</div>
												<div class="item-info">
													<div class="item-basic-info">
														<a href="#" target="_blank" title="{{$v->good->title}}" class="item-title J_MakePoint" data-point="tbcart.8.11">{{$v->good->title}}</a>
													</div>
												</div>
											</li>
											<li class="td td-info">
												<div class="item-props item-props-can">

													@foreach($v->huowu->attrgroup($v->huowu->id) as $vv)
														<span class="sku-line">{{$vv['attr']}}: {{$vv['sonattr']}}</span>
														<br>
													@endforeach


													<i class="theme-login am-icon-sort-desc"></i>
												</div>
											</li>
											<li class="td td-price">
												<div class="item-price price-promo-promo">
													<div class="price-content">
														<div class="price-line">
															<em class="price-original">
																{{$v->good->goodprice}}
															</em>
														</div>
														<div class="price-line">
															<em class="J_Price price-now" tabindex="0">
																{{$v->good->mallprice+$v->huowu->fujiaprice}}
															</em>
														</div>
													</div>
												</div>
											</li>
											<li class="td td-amount">
												<div class="amount-wrapper ">
													<div class="item-amount ">
														<div class="sl">
															<input id="min" class="min am-btn" name="" type="button" value="-" onclick="mini(this)"/>
															<input id="text_box" class="text_box" name="" type="text" value="1" style="width:30px;" />
															<input id="add" class="add am-btn" name="" type="button" value="+" onclick="add(this)" />
														</div>
													</div>
												</div>
											</li>
											<li class="td td-sum">
												<div class="td-inner">
													<em tabindex="0" class="J_ItemSum number xiaoji">{{$v['xiaoji']}}</em>
												</div>
											</li>
											<li class="td td-op">
												<div class="td-inner">
													{{--<a title="移入收藏夹" class="btn-fav" href="{{route('shoucang',$v)}}">移入收藏夹</a>--}}
													<a  href="javascript:;" data-point-url="#" class="delete" onclick="del(this,{{$v['id']}})">
														删除</a>
												</div>
											</li>
										</ul>

									</div>

								@endforeach


							</div>
						</tr>






					<div class="clear"></div>





				</div>
				<div class="clear"></div>

				<div class="float-bar-wrapper">
					<div id="J_SelectAll2" class="select-all J_SelectAll">
						<div class="cart-checkbox">
							<input class="check-all check" id="J_SelectAllCbx2" name="select-all" value="true" type="checkbox">
							<label for="J_SelectAllCbx2"></label>
						</div>
						<span>全选</span>
					</div>
					<div class="float-bar-right">
						<div class="amount-sum">
							<span class="txt">已选商品</span>
							<em id="J_SelectedItemsCount">0</em><span class="txt">件</span>
							<div class="arrow-box">
								<span class="selected-items-arrow"></span>
								<span class="arrow"></span>
							</div>
						</div>
						<div class="price-sum">
							<span class="txt">合计:</span>
							<strong class="price">¥<em id="J_Total"></em></strong>
						</div>
						<div class="btn-area">
							<a  href="{{route('order')}}" id="J_Go" class="submit-btn submit-btn-disabled" aria-label="请注意如果没有选择宝贝，将无法结算">
								<span>结&nbsp;算</span></a>
						</div>
					</div>

				</div>


			</div>

			@else

				<div class="concent">
					<div style="width: 100%;height: 150px;text-align: center;margin-top: 25px">
						<h1>购物车里空空如也...</h1>
						<a href="/" style="color: red;font-size: 25px;font-weight:bold">快去购物吧!>>></a>
					</div>
				</div>


				@endif


			<script>


				$(function () {
					zongjia();

				    // 全选
					$('#J_SelectAllCbx2').click(function () {
						// alert(123);
                        if($(this).attr("checked")){
                            $(".bundle-main input[name=items]").each(function () {
                                $(this).attr("checked", true);
                            });

                            GetCount();

                        }
                        else
                        {
                            $(".bundle-main input[name=items]").each(function () {
                                if ($(this).attr("checked")) {
                                    $(this).attr("checked", false);
                                } else {
                                    $(this).attr("checked", true);
                                }

                            });
                            GetCount();
                        }
                    })


                });

				// 计算总价
				// function zongjia(){
                //     var total = 0;
                // $.each($('.xiaoji'),function (k, v) {
                //     total += $(v).html() * 1;
                // });
                // $('#J_Total').html(total);
                // }
				// 加号
                function add(obj) {
                    //获取数量的值
                    var num = $(obj).siblings('.text_box').val();
                    num++;
                    //获取单价
                    var danjia = $(obj).parents('.td-amount').siblings('.td-price').find('.price-now').html();
                    //计算小计
                    var xiaoji = danjia * num;
                    //将小计的值赋值给当前点击的这个加号的父亲的兄弟里面的小计值
                    $(obj).parents('.td-amount').siblings('.td-sum').find('.xiaoji').html(xiaoji);
                    //调用一下计算总价
                    zongjia();
                }
                function mini(obj) {
                    //获取数量的值
                    var num = $(obj).siblings('.text_box').val();
                    num++;
                    //获取单价
                    var danjia = $(obj).parents('.td-amount').siblings('.td-price').find('.price-now').html();
                    //计算小计
                    var xiaoji = danjia * num;
                    //将小计的值赋值给当前点击的这个加号的父亲的兄弟里面的小计值
                    $(obj).parents('.td-amount').siblings('.td-sum').find('.xiaoji').html(xiaoji);
                    //调用一下计算总价
                    zongjia();
                }

				function zongjia() {
                    var total = 0;
                    $.each($('.xiaoji'),function (k, v) {
                        total += $(v).html() * 1;
                    });
                    $('#J_Total').html(total);
                }

                // 计算总价
                function GetCount() {
                    var conts = 0;
                    var aa = 0;
                    // var total = 0;
                    $(".bundle-main input[name=items]").each(function () {
                        if ($(this).attr("checked")) {
                            for (var i = 0; i < $(this).length; i++) {
                                conts += parseInt($(this).val());
                                aa += 1;
                            }

                            // $.each($('.xiaoji'),function (k, v) {
                            //     total += $(v).html() * 1;
                            // });
                            // $('#J_Total').html(total);

                        }else {

                            // $('#J_Total').html(0);

                        }
                    });
                    $("#J_SelectedItemsCount").text(aa);
                    // $("#J_Total").html((conts).toFixed(2));
                }





                // function add(obj) {
                //     var num = $(obj).siblings('.text_box').val();
                //     // alert(num);
                //     var danjia = $(obj).parents('li.td').siblings('li.td-price').find('.J_Price').html();
				//
                //     $(obj).parents('li.td').siblings('li.td-sum').find('.J_ItemSum ').html(danjia*num);
                //     // console.log(parseFloat(danjia));
                //     // alert(danjia);
                //     // setTotal(); GetCount();
                //     // $('#J_Total').html(danjia)
				//
                // }
                // // 减少数量
                // function mini(obj) {
                //     // alert(123);
                //     var num = $(obj).siblings('.text_box').val();
                //     // alert(num);
                //     var danjia = $(obj).parents('li.td').siblings('li.td-price').find('.J_Price').html();
                //     $(obj).parents('li.td').siblings('li.td-sum').find('.J_ItemSum ').html(danjia*num);
                //     // console.log(parseFloat(danjia));
                //     // alert(danjia);
                //     // setTotal(); GetCount();
                // }
                $(".bundle-main input[name=items]").click(function () {
                    // $("#total2").html() = GetCount($(this));
                    GetCount();
                    //alert(conts);
                });


                // 商品数量更改价格
                // var t = $(".text_box");
                // $(".add").click(function () {
                    // alert(123);
                    // t.val(parseInt(t.val()) + 1)
                    // setTotal(); GetCount();
                // })
                // $(".min").click(function () {
                //     if(t.val()>0){
                //         t.val(parseInt(t.val()) - 1)
                //         setTotal(); GetCount();
                //     }
                // })
                // function setTotal() {
                //     // $(".J_ItemSum").html((parseInt(t.val()) * danjia).toFixed(2));
                //     // $(".haha").val(parseInt(t.val()) * danjia);
				//
                //     GetCount;
                // }
                // setTotal();

				// 购物车删除，js删除
				function del(obj,id) {
				    // alert(id);
                    $.ajax({
                        url:"/del/"+id,
                        type:"get",
                        success:function (res) {
                            // console.log(data)
							// console.log(res)
							// ajax异步删除
							if (res) {
								$(obj).parents('.bundle-main').remove();
							}
                        }
                    });
                }

			</script>

			<!--操作页面-->

			<div class="theme-popover-mask"></div>


		<!--引导 -->
		<div class="navCir">
			<li><a href="home.html"><i class="am-icon-home "></i>首页</a></li>
			<li><a href="sort.html"><i class="am-icon-list"></i>分类</a></li>
			<li class="active"><a href="shopcart.html"><i class="am-icon-shopping-basket"></i>购物车</a></li>	
			<li><a href="/templates/hd/assets/person/index.html"><i class="am-icon-user"></i>我的</a></li>					
		</div>

			@endsection